Strict

Import agfx

Global myTmpScreen:TTmpScreen

Class TAgfx_test_app Extends TFramework

	Method OnCreate:Int()
		
		Super.OnCreate()
				
		DISPLAY.SetVirtualSize(480,320)
		
		myTmpScreen = New TTmpScreen		
		myTmpScreen.Prepare()
		
		Return 0
	End
	

	
End


Class TTmpScreen Extends TScreen
	
Const BOX_COEF:Float = 1.0
Const BOX_MASS:Float = 30


	Field World:TVerletWorld = New TVerletWorld()
	Field box_2:TVerletGroup
	
	Field rope1:TVerletGroup
	Field rope2:TVerletGroup
	
	Field circle:TVerletGroup
	
	Field gravity:TVector2 = New TVector2(0,5)
	' START when app is created
	Method Start:Void()
	
		Self.World.SetGravity(gravity)
		
		Local w_center:TVector2 = New TVector2(DISPLAY.VSCREEN_HALF_WIDTH,DISPLAY.VSCREEN_HALF_HEIGHT)
		Self.World.SetRange(w_center,DISPLAY.VSCREEN_WIDTH,DISPLAY.VSCREEN_HEIGHT)

		Self.box_2 = New TVerletGroup(gravity,True)
		Self.box_2.CreateRectangle(240,32,128,32,20,1.0)
				
		Self.rope1 = New TVerletGroup(gravity,True)
		Self.rope1.CreateRope(50,90,False,430,250,False,2,10,1)		
		
		
		Self.rope2 = New TVerletGroup(gravity,True)
		Self.rope2.CreateRope(430,90,False,50,280,False,2,10,1)		
	
		Self.circle = New TVerletGroup(gravity,True)	
		Self.circle.CreateCircle(50,50,True,32,8,20,1.0)
		
		Self.World.AddGroup(Self.rope1)
		Self.World.AddGroup(Self.rope2)		
		Self.World.AddGroup(Self.box_2)
		Self.World.AddGroup(Self.circle)
		
	End
	
	' main app logic loop update
	Method Update:Void()

		Self.World.Update()
	
		If KeyHit (KEY_UP) Then Self.box_2.Translate( 0,-4)
		
		If KeyHit (KEY_LEFT) Then Self.box_2.Rotate( -2)
		If KeyHit (KEY_RIGHT) Then Self.box_2.Rotate( 2)
		

	End
	
	' main app render loop
	Method Render:Void()
		Cls
		Self.World.Render()
		
		DrawText("LEFT/RIGHT = rotate | UP = translate up | SPACE = start/stop",0,0)
	End
End
